import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Router} from '@angular/router';
import {AppService} from '../../service/app/app.service';

@Component({
    selector: 'app-forget-password',
    templateUrl: './change-password.component.html',
    styleUrls: ['./change-password.component.css']
})
export class ChangePasswordComponent implements OnInit {
    validateForm: FormGroup;
    changeImg = require('../../../assets/change_pwd.png');

    constructor(private builder: FormBuilder,
                private fb: FormBuilder,
                private appService: AppService,
                private router: Router) {
    }

    ngOnInit() {
        this.validateForm = this.fb.group({
            oldpwd: [null, [Validators.required]],
            pwd: [null, [Validators.required]],
            repwd: [null, [Validators.required]],
        });
    }
  enterRegister() {
    this.router.navigate(['register']).catch();
  }
  enterLogin() {
    this.router.navigate(['login']).catch();
  }
    changePassword() {
        this.appService.post(this.appService.urls.update + localStorage.getItem('user_id') + '?access_token=' + localStorage.getItem('token'),
            this.validateForm.value).subscribe((resp: any) => {
            console.log(resp);
            // const userInfo = resp;
            // console.log(userInfo);
            // if (userInfo.ret === 1) {
            //   localStorage.setItem('email', this.validateForm.value.email);
            //   localStorage.setItem('passwd', this.validateForm.value.passwd);
            //   localStorage.setItem('token', userInfo.data.token);
            //   localStorage.setItem('user_id', userInfo.data.user_id);
            //   localStorage.setItem('status', 'off');
            //   this.router.navigate(['home']).catch();
            // } else {
            //   this.showMessage = true;
            //   this.errorMessage = userInfo.msg;
            //   this.hideErrorMessage(1000);
            // }
        });
    }

}
